package cn.yunhe.servlet;

import cn.yunhe.biz.BoardService;
import cn.yunhe.pojo.Board;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/BoardAddServlet")
public class BoardAddServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String boardname = request.getParameter("boardname");
        BoardService boardService=new BoardService();
        int flag= boardService.addBoard(new Board(boardname));

        if (flag>0){
            request.getRequestDispatcher("main.jsp").forward(request,response);
        }else {
            response.sendRedirect("addBoard.html");
        }

    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    public static class Page {
        private int startPage;
        private int endPage;
        private String keyword;

        public Page() {
        }

        public Page(int startPage, int endPage) {
            this.startPage = startPage;
            this.endPage = endPage;
        }

        public String getKeyword() {
            return keyword;
        }

        public void setKeyword(String keyword) {
            this.keyword = keyword;
        }

        public Page(int startPage, int endPage, String keyword) {
            this.startPage = startPage;
            this.endPage = endPage;
            this.keyword = keyword;
        }

        public int getStartPage() {
            return startPage;
        }

        public void setStartPage(int startPage) {
            this.startPage = startPage;
        }

        public int getEndPage() {
            return endPage;
        }

        public void setEndPage(int endPage) {
            this.endPage = endPage;
        }
    }
}
